package com.bba.manager.user.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.AES;
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bba.manager.common.model.user.Customer;
import com.bba.manager.common.model.user.VO.customerPageVO;
import com.bba.manager.common.util.EncryptHandler;
import com.bba.manager.common.util.EncryptUtils;
import com.bba.manager.common.util.ResponseEnum;
import com.bba.manager.common.util.ResponseVO;
import com.bba.manager.user.mapper.CustomerMapper;
import com.bba.manager.user.service.ICustomerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author SYANDZZY
 * @since 2025-08-11
 */
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements ICustomerService {
    @Override
    public void saveCustomer(Customer customer) {
        LambdaQueryChainWrapper<Customer> wrapper=new LambdaQueryChainWrapper<>(baseMapper);

        Customer one = wrapper.eq(Customer::getIdCard, customer.getIdCard()).one();
        if (one!=null){
            throw new RuntimeException(ResponseEnum.USER_HAS_EXISTED.getMessage());
        }

       this.save(customer);
    }

    @Override
    public IPage listCustomer(customerPageVO customerPageVO) {
        Page<Customer> page=new Page<>(customerPageVO.getPage(),customerPageVO.getLimit());
        return this.page(page);

    }

    @Override
    public List<Customer> listCustomerByName(String name) {
        LambdaQueryChainWrapper<Customer> wrapper=new LambdaQueryChainWrapper<>(baseMapper);
        return wrapper.eq(Customer::getName,name).list();
    }


}
